//
//  ChoiceBankViewController.m
//  MemberProject
//
//  Created by vincent luo on 15/7/21.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "ChoiceBankViewController.h"

@interface ChoiceBankViewController ()
@property (nonatomic,strong)NSArray *searchArr;
@end

@implementation ChoiceBankViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"选择分行";
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.mainTableView) {
        return self.dataArr.count;
    }else{
        // 谓词搜索
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self contains [cd] %@",self.searchBar.text];
        self.searchArr=  [[NSArray alloc] initWithArray:[self.dataArr filteredArrayUsingPredicate:predicate]];
        return self.searchArr.count;
    }
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellStr = @"cellStr";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    if (tableView == self.mainTableView) {
        cell.textLabel.text = self.dataArr[indexPath.row];
    }else{
        cell.textLabel.text = self.searchArr[indexPath.row];
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.mainTableView)
    {
        
        self.fBlock(self.dataArr[indexPath.row]);
        
    }
    else
    {
        self.fBlock(self.searchArr[indexPath.row]);
    
    }
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)finishChoice:(finishChoiceBlock)block
{
    self.fBlock = block;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
